import sys

def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def plus_minus(n, st):
    while True:
        n += st
        if is_prime(n):
            return n
            break

numbers = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9
}

try:
    x = input('').split()
    x = [str(numbers[word]) for word in x]
    x1 = int(''.join(x))

    if x1 < 100 or x1 > 999:
        print('Wrong input')
        sys.exit()

    simple_one = plus_minus(x1, -1)
    simple_two = plus_minus(x1, 1)

    if x1 - simple_one < simple_two - x1:
        print(simple_one)
    elif x1 - simple_one > simple_two - x1:
        print(simple_two)
    else:
        print(min(simple_one, simple_two))

except KeyError:
    print("Wrong input")